#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;

    unordered_map<string, vector<string>> incompatible;
    for (int i = 0; i < N; ++i) {
        string item1, item2;
        cin >> item1 >> item2;
        incompatible[item1].push_back(item2);
        incompatible[item2].push_back(item1);
    }

    for (int i = 0; i < M; ++i) {
        int K;
        cin >> K;
        unordered_set<string> items;
        for (int j = 0; j < K; ++j) {
            string item;
            cin >> item;
            items.insert(item);
        }
        bool safe = true;
        for (const auto& item : items) {
            if (incompatible.find(item) != incompatible.end()) {
                for (const auto& incompatible_item : incompatible[item]) {
                    if (items.find(incompatible_item) != items.end()) {
                        safe = false;
                        break;
                    }
                }
            }
            if (!safe) break;
        }
        if (safe) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}    